/**
 * FssProperties.java
 */
package fss.core.config;

import java.util.ResourceBundle;
import java.util.logging.Level;

import fss.util.FssUtils;

/**
 * The wrapper around the FSS properties file.
 * 
 * @author thinh
 *
 */
public class FssProperties {
    /**
     * The properties filename.
     */
    private static final String FSS_PROPERTIES = "fss.core.config.fss";
    /**
     * The remote service homedir key.
     */
    private static final String SERVICE_HOMEDIR = "fss.remote.service.home";
    /**
     * The client homedir key.
     */
    private static final String CLIENT_HOMEDIR = "fss.remote.client.home";
    /**
     * The remote service logfile suffix key.
     */
    private static final String SERVICE_LOGFILE_SUFFIX = "fss.logger.service.file.suffix";
    /**
     * The service registry homedir key.
     */
    private static final String REGISTRY_HOMEDIR = "fss.remote.registry.home";
    /**
     * The service registry logfile suffix key.
     */
    private static final String REGISTRY_LOGIFLE_SUFFIX = "fss.logger.registry.file.suffix";
    /**
     * The client logfile suffix key.
     */
    private static final String CLIENT_LOGFILE_SUFFICE = "fss.logger.client.file.suffix";
    /**
     * The application logger home directory.
     */
    private static final String FSS_LOGGER_HOMEDIR = "fss.logger.home";
    /**
     * The application logger log filename.
     */
    private static final String FSS_LOGFILE_NAME = "fss.logger.filename";
    /**
     * The interval to heartbeat the service registry (in seconds).
     */
    private static final String FSS_REGISTRY_HEARTBEAT_INTERVAL = "fss.registry.heartbeat.interval";
    /**
     * The chunk size of each file transfer.
     */
    private static final String FSS_TRANSFER_CHUNKSIZE = "fss.transfer.chunksize";
    /**
     * Client poll time.
     */
    private static final String FSS_CLIENT_POLLTIME = "fss.client.polltime";
    /**
     * Registry poll time.
     */
    private static final String FSS_REGISTRY_POLLTIME = "fss.registry.polltime";
    /**
     * Logger level.
     */
    private static final String LOGGER_LEVEL = "fss.logger.level";
    /**
     * The properties file.
     */
    private ResourceBundle properties = null;
    /**
     * The singleton.
     */
    private static FssProperties singleton = null;
    /**
     * Constructor.
     */
    private FssProperties() {
        properties = ResourceBundle.getBundle(FSS_PROPERTIES);
    }
    /**
     * Singleton getter.
     * @return the singleton.
     */
    public static FssProperties getInstance() {
        if(singleton == null) {
            singleton = new FssProperties();
        }
        return singleton;
    }
    /**
     * Get the client homedir.
     * @param name client name;
     * @return the path.
     */
    public String getClientHomeDir(String name) {
        return properties.getString(CLIENT_HOMEDIR) + "/" + name;
    }
    /**
     * Get the remote service homedir.
     * @param name remote service id;
     * @return the path.
     */
    public String getRemoteServiceHomeDir(String name) {
        return properties.getString(SERVICE_HOMEDIR) + "/" + name;
    }
    /**
     * Get the service registry homedir.
     * @param name service registry id;
     * @return the path.
     */
    public String getServiceRegistryHomeDir(String name) {
        return properties.getString(REGISTRY_HOMEDIR) + "/" + name;
    }
    /**
     * Get the filename for the remote service log file.
     * @param id the remote service id.
     * @return the filename.
     */
    public String getRemoteServiceLogFilename(String name) {
        return name + properties.getString(SERVICE_LOGFILE_SUFFIX);
    }
    /**
     * Get the filename for the service registry log file.
     * @param id the service registry id.
     * @return the filename.
     */
    public String getServiceRegistryLogFilename(String name) {
        return name + properties.getString(REGISTRY_LOGIFLE_SUFFIX);
    }
    /**
     * Get the filename for the client log file.
     * @param name
     * @return the log filename.
     */
    public String getClientLogFilename(String name) {
        return name + properties.getString(CLIENT_LOGFILE_SUFFICE);
    }
    /**
     * Get the fully qualified file path of the log file (including homedir).
     * @param name the id.
     * @return the full path.
     */
    public String getClientFullyQualifiedLogFile(String name) {
        return getClientHomeDir(name) + "/logs/" + FssUtils.getSystemFileSeparator() + getClientLogFilename(name);
    }
    /**
     * Get the fully qualified file path of the log file (including homedir).
     * @param name the id.
     * @return the full path.
     */
    public String getRemoteServiceFullyQualifiedLogFile(String name) {
        return getRemoteServiceHomeDir(name) + "/logs/" +  FssUtils.getSystemFileSeparator() + getRemoteServiceLogFilename(name);
    }
    /**
     * Get the fully qualified file path of the log file (including homedir).
     * @param name the id.
     * @return the full path.
     */
    public String getServiceRegistryFullyQualifiedLogFile(String name) {
        return getServiceRegistryHomeDir(name) + "/logs/" + getServiceRegistryLogFilename(name);
    }
    /**
     * Get the FSS application log homedir.
     * @return the path.
     */
    public String getFssApplicationLogHomeDir() {
        return properties.getString(FSS_LOGGER_HOMEDIR);
    }
    /**
     * Get the FSS application log filename.
     * @return the filename.
     */
    public String getFssApplicationLogFilename() {
        return properties.getString(FSS_LOGFILE_NAME);
    }
    /**
     * Get the fully qualified file path of the log file (including homedir).
     * @return the full path.
     */
    public String getFssApplicationFullyQualifiedLogFile() {
        return getFssApplicationLogHomeDir() + "/" + getFssApplicationLogFilename();
    }
    /**
     * Get the interval to heartbeat the service registry (in seconds).
     * @return the heartbeat interval (in seconds).
     */
    public int getServiceRegistryHeartbeatInterval() {
        return Integer.parseInt(properties.getString(FSS_REGISTRY_HEARTBEAT_INTERVAL));
    }
    /**
     * Get the chunksize of each file transfer (download, upload).
     * @return the chunksize in bytes.
     */
    public int getFileTransferChunksize() {
        return Integer.parseInt(properties.getString(FSS_TRANSFER_CHUNKSIZE));
    }
    /**
     * Get the registry poll time (seconds).
     * @return seconds.
     */
    public int getRemoteRegistryPollTime() {
        return Integer.parseInt(properties.getString(FSS_CLIENT_POLLTIME));
    }
    /**
     * Get the client poll time (seconds).
     * @return seconds.
     */
    public int getRemoteClientPollTime() {
        return Integer.parseInt(properties.getString(FSS_REGISTRY_POLLTIME));
    }
    public Level getLoggerLevel() {
        return Level.parse(properties.getString(LOGGER_LEVEL));
    }
}
